package com.fyy.utils.imgCode;

import com.wf.captcha.utils.CaptchaUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * @Author fyy
 * @Description 图形验证码
 * @Date 2021/3/8 11:18
 */
@Controller
public class ImgCode {

    @ResponseBody
    @RequestMapping("/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("******************");
        CaptchaUtil.out(request, response);
    }

    @PostMapping("/login")
    public Object login(HttpServletRequest request,String username, String password, String verCode){
        if (!CaptchaUtil.ver(verCode, request)) {
            // 清除session中的验证码
            CaptchaUtil.clear(request);
            return "验证码不正确";
        }
        return null;
    }

}
